package com.example.help.myapplication;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;

import com.java.com.study7a4.WebServiceActivity;
import com.java.com.study8a2a1.BitmapActivity1;
import com.nami.game_1945.MainGame;


public class MainActivity extends AppCompatActivity implements  View.OnClickListener {

    private Button btn1;
    private Button btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        buttonInit();

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//                        .setAction("Action", null).show();

//                requestWindowFeature(Window.FEATURE_NO_TITLE);//设置窗口没有标题
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏显示
                Init();

            }
        });
    }

    private void buttonInit()
    {
        btn1=(Button) findViewById(R.id.btn1);
        btn1.setOnClickListener(this);
        btn2=(Button) findViewById(R.id.btn2);
        btn2.setOnClickListener(this);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    public void Init(){
        WindowManager wm = this.getWindowManager();
        Display display = wm.getDefaultDisplay();
        MainGame gameView = new MainGame(this, display);
        gameView.setBackgroundColor(Color.BLACK);
        this.setContentView(gameView);
    }


    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.btn1:

//                Toast.makeText(this,"lik",Toast.LENGTH_SHORT).show();
//                startActivity(new Intent(this,Main2Activity.class ));
//                startActivity(new Intent(this, HttpURLConnectionActivity.class));
//                startActivity(new Intent(this, WebViewActivity.class));
                startActivity(new Intent(this, BitmapActivity1.class   ));
                break;

            case R.id.btn2:
//                startActivity(new Intent(this, WebViewActivity.class));

                startActivity(new Intent(this, WebServiceActivity.class));

//                Display myDisplay=this.getWindowManager().getDefaultDisplay();
//                MyView1 myView1=new MyView1(this);
//                this.setContentView(myView1);
//                ColorDrawable drawable=new ColorDrawable(0xffff2200);
//                myView1.setBackground(drawable);
//
//                try {
//                    Thread.sleep(1000);
//                    Toast.makeText(this,"color",Toast.LENGTH_SHORT).show();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                    Toast.makeText(this,"colorError",Toast.LENGTH_SHORT).show();
//                }
//
//                myView1.setBackgroundColor(getResources().getColor(R.color.likColor1));


                break;
            default:
                break;
        }

    }
}
